
using System.Data.SqlClient;
using OpenSoftStore.Client.SFL;
using OpenSoftStore.Orm.Static;

namespace Crm.UI.Setting.Backup
{
	public class SqlServerBackup : BackupInterface
	{
		private SqlHelper _sqlHelper = new SqlHelper();
		public void BackupDataBase(string currentFile, string backupFile)
		{
			if (true)
			{
			}
			SqlConnection sqlConnection = new SqlConnection();
			SqlCommand sqlCommand = new SqlCommand();
			//sqlConnection.ConnectionString = BaseConn.ConnStr;
			sqlConnection.Open();
			sqlCommand.Connection = sqlConnection;
			sqlCommand.CommandText = string.Concat(new string[]
			{
				"BACKUP DATABASE  \"",
				SystemInfo.DataName,
				"\"  TO DISK ='",
				backupFile,
				"' with init"
			});
			sqlCommand.ExecuteNonQuery();
			sqlCommand.Dispose();
			sqlConnection.Dispose();
			sqlConnection.Close();
		}
		public void RecoveDataBase(string backupFile, string currentFile)
		{
			if (true)
			{
			}
			SqlConnection sqlConnection = new SqlConnection();
			SqlCommand sqlCommand = new SqlCommand();
			//sqlConnection.ConnectionString = BaseConn.ConnStr;
			sqlConnection.Open();
			sqlCommand.Connection = sqlConnection;
			sqlCommand.CommandText = string.Concat(new string[]
			{
				"ALTER DATABASE ",
				SystemInfo.DataName,
				" SET SINGLE_USER WITH ROLLBACK IMMEDIATE  use master RESTORE DATABASE \"",
				SystemInfo.DataName,
				"\" FROM DISK='",
				backupFile,
				" ' with replace ALTER DATABASE ",
				SystemInfo.DataName,
				" SET MULTI_USER WITH ROLLBACK IMMEDIATE"
			});
			sqlCommand.ExecuteNonQuery();
			sqlCommand.Dispose();
			sqlConnection.Dispose();
			sqlConnection.Close();
		}
	}
}
